/*  -*- mode: c++; coding: utf-8; c-file-style: "stroustrup"; -*-

    Copyright 2008 Asier Aguirre <asier.aguirre@gmail.com>
    This file is part of Intromit.

    Intromit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Intromit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Intromit.  If not, see <http://www.gnu.org/licenses/>.
*/

// INCLUDES
#include "render_util.hh"
#include "ogl.hh"
#include <math.h>

void render_util::render_sphere(float radius, int n_parallels, int n_parpoints, int n_meridians, int n_merpoints)
{
    float ang_mult_points=M_PI*(360.0/180.0)/(float)n_parpoints;
    float ang_mult=M_PI*(360.0/180.0)/(float)n_parallels*0.5;
    for(int i=0; i<n_parallels; i++)
    {
	glBegin(GL_LINE_LOOP);
	float ang=((float)i+0.5)*ang_mult;
	float elev=radius*cos(ang);
	float rad=radius*sin(ang);
	for(int j=0; j<n_parpoints; j++)
	{
	    ang=(float)j*ang_mult_points;
	    glVertex3f(rad*sinf(ang), elev, rad*cosf(ang));
	}
	glEnd();
    }

    ang_mult_points=M_PI*(360.0/180.0)/(float)n_merpoints;
    ang_mult=M_PI*(360.0/180.0)/(float)n_meridians*0.5;
    for(int i=0; i<n_meridians; i++)
    {
	glBegin(GL_LINE_LOOP);
	float ang=(float)i*ang_mult;
	float x=radius*sin(ang);
	float y=radius*cos(ang);
	for(int j=0; j<n_merpoints; j++)
	{
	    ang=(float)j*ang_mult_points;
	    float elev=radius*cos(ang);
	    float coelev=sin(ang);
	    glVertex3f(x*coelev, elev, y*coelev);
	}
	glEnd();
    }
}

